#include <buola/gui.h>

#include <buola/gui/cicon.h>

#include <buola/widgets/clbrenderer.h>
#include <buola/widgets/clistbox.h>

namespace buola { namespace gui {

CLBRenderer::CLBRenderer(CListBox *pListBox)
{
	mListBox=pListBox;
}

CLBRenderer::~CLBRenderer()
{
}

CListBox::SItem *CLBRenderer::GetItemAt(const CPoint_d &pPoint,int *pType)
{
	for(int i=0;i<mListBox->GetItemCount();i++)
	{
		CListBox::SItem *lI=mListBox->GetItems()[i];
		
		int lType=HitTestItem(lI,pPoint);

		if(lType&LBHT_SELECT)
		{
			if(pType) *pType=lType;
			return lI;
		}
	}
	
	return nullptr;
}

int CLBRenderer::GetItemsIn(const CRect_d &pRect,CListBox::SItem *pItems[])
{
	int lNumItems=0;

	for(int i=0;i<mListBox->GetItemCount();i++)
	{
		CListBox::SItem *lI=mListBox->GetItems()[i];
		
		if(HitTestItem(lI,pRect))
			pItems[lNumItems++]=lI;
	}
	
	return lNumItems;
}

/*namespace gui*/ } /*namespace buola*/ }
